package GUI;

import java.util.ArrayList;

import javax.swing.JFrame;
import javax.swing.table.AbstractTableModel;

import ModelLayer.Product;
import ModelLayer.SalesOrderLine;

public class ProductSalesTable extends AbstractTableModel {


	/**
	 * Launch the application.
	 */


	/**
	 * Create the application.
	 */
	public ProductSalesTable() 
	{
		data = new ArrayList<Product>();
	}
	

		private String[] columnNames = { "ProductNumber", "ProductName", "SalesPrice",
				"ProductType", "amount" };
		
		private ArrayList<Product> data;
		
		private String SOL;

		//Sets the products
		public void setProducts(ArrayList<Product> products) 
		{
			data = products;
			fireTableDataChanged();
		}
		
		//Adds the products
		public void addProduct(Product product)
		{
			data.add(product);
			fireTableDataChanged();
		}
		
		//Sets the amount
		public void setAmount(String string)
		{
			SOL = string;
			fireTableDataChanged();
		}

		//Method does so table cannot be edited
		public boolean isCellEditable(int row, int col) 
		{
			return false;
		}

		//Returns column count
		public int getColumnCount() 
		{
			return columnNames.length;
		}

		//Returns row count
		public int getRowCount() 
		{
			return data.size();
		}

		//Returns column name
		public String getColumnName(int col) 
		{
			return columnNames[col];
		}

		//Returns the product values to the table
		public Object getValueAt(int row, int col) 
		{

			Product product = data.get(row);
			String sol = SOL;

			switch (col) {

			case 0:
				return product.getProductNumber();
			case 1:
				return product.getProductName();
			case 2:
				return product.getSalesPrice();
			case 3:
				return product.getProductType();
			case 4:
				return sol;
			default:
				return null;

			}

		}
}
